import com.powerfl.frm.taf.*;

import flash.display.BitmapData;
import flash.text.*;

private var _paramText:String = '';
private var _paramWidth:Number = 0;
private var _paramHeight:Number = 0;
private var _paramTextField:TextField;
private var _paramTextFormat:TextFormat;

private function paramTextSet():void{
	if( SELF._paramTextField === null ){
		SELF._paramTextField = new TextField;
		SELF._paramTextFormat = new TextFormat;
		SELF._paramTextField.type = TextFieldType.DYNAMIC;
		SELF._paramTextField.autoSize = TextFieldAutoSize.LEFT;
		SELF._paramTextField.antiAliasType = AntiAliasType.ADVANCED;
		SELF._paramTextField.multiline = true;
		SELF._paramTextField.selectable = false; 
		SELF._paramTextField.tabEnabled = false;
		SELF._paramTextFormat.color = 0;
		SELF._paramTextFormat.size = 12;
	}
}
final public function $textGet( ...$textParam ):BitmapData{
	return $textApply();
}
private function $textApply():BitmapData{
	var result:BitmapData
	SELF._paramTextField.defaultTextFormat = SELF._paramTextFormat;
	SELF._paramTextField.htmlText = SELF._paramText;
//	SELF._paramTextField.setTextFormat( SELF._paramTextFormat );
	
	if( SELF._paramWidth > 0 ){
		SELF._paramTextField.width = SELF._paramWidth;
		SELF._paramTextField.height = SELF._paramHeight;
	}else{
		SELF._paramTextField.width = SELF._paramTextField.textWidth;
		SELF._paramTextField.height = SELF._paramTextField.textHeight;
	}
	result = bitmapDraw( null, SELF._paramTextField );
	
	SELF._paramText = '';
	SELF._paramTextField = null;
	SELF._paramTextFormat = null;
	SELF._paramWidth = SELF._paramHeight = 0;
	return result;
}
final public function $textFontText( $font:String, $isEmbed:Boolean = false ):String{
	paramTextSet();
	SELF._paramTextField.embedFonts = $isEmbed;
	SELF._paramTextFormat.font =$font;
	return '@@textfield';
}
final public function $textAutoSizeCenter():String{
	paramTextSet();
	SELF._paramTextField.autoSize = TextFieldAutoSize.CENTER;
	return '@@textfield';
}
final public function $textAutoSizeLeft():String{
	paramTextSet();
	SELF._paramTextField.autoSize = TextFieldAutoSize.LEFT;
	return '@@textfield';
}
final public function $textAutoSizeRight():String{
	paramTextSet();
	SELF._paramTextField.autoSize = TextFieldAutoSize.RIGHT;
	return '@@textfield';
}
final public function $textAutoSizeNone():String{
	paramTextSet();
	SELF._paramTextField.autoSize = TextFieldAutoSize.NONE;
	return '@@textfield';
}
final public function $textMultilineTrue():String{
	paramTextSet();
	SELF._paramTextField.multiline = true;
	return '@@textfield';
}
final public function $textMultilineFalse():String{
	paramTextSet();
	SELF._paramTextField.multiline = false;
	return '@@textfield';
}
final public function $textWordWrapTrue():String{
	paramTextSet();
	SELF._paramTextField.wordWrap = true;
	return '@@textfield';
}
final public function $textWordWrapFalse():String{
	paramTextSet();
	SELF._paramTextField.wordWrap = false;
	return '@@textfield';
}
final public function $textBoldTrue():String{
	paramTextSet();
	SELF._paramTextFormat.bold = true;
	return '@@textfield';
}
final public function $textBoldFalse():String{
	paramTextSet();
	SELF._paramTextFormat.bold = false;
	return '@@textfield';
}
final public function $textUnderlineTrue():String{
	paramTextSet();
	SELF._paramTextFormat.underline = true;
	return '@@textfield';
}
final public function $textUnderlineFalse():String{
	paramTextSet();
	SELF._paramTextFormat.underline = false;
	return '@@textfield';
}
final public function $textItalicTrue():String{
	paramTextSet();
	SELF._paramTextFormat.italic = true;
	return '@@textfield';
}
final public function $textItalicFalse():String{
	paramTextSet();
	SELF._paramTextFormat.italic = false;
	return '@@textfield';
}
final public function $textLeading( $leading:Number ):String{
	paramTextSet();
	SELF._paramTextFormat.leading = $leading;
	return '@@textfield';
}
final public function $textColor( $color:uint ):String{
	paramTextSet();
	SELF._paramTextFormat.color = $color;
	return '@@textfield';
}
final public function $textFontSize( $size:uint ):String{
	paramTextSet();
	SELF._paramTextFormat.size = $size;
	return '@@textfield';
}
final public function $textLetterSpacing( $letterSpacing:uint ):String{
	paramTextSet();
	SELF._paramTextFormat.letterSpacing = $letterSpacing;
	return '@@textfield';
}
final public function $textAlignCenter():String{
	paramTextSet();
	SELF._paramTextFormat.align = TextFormatAlign.CENTER;
	return '@@textfield';
}
final public function $textAlignLeft():String{
	paramTextSet();
	SELF._paramTextFormat.align = TextFormatAlign.LEFT;
	return '@@textfield';
}
final public function $textAlignRight():String{
	paramTextSet();
	SELF._paramTextFormat.align = TextFormatAlign.RIGHT;
	return '@@textfield';
}
final public function $textHtml( $html:String ):String{
	paramTextSet();
	SELF._paramText = $html;
	return '@@textfield';
}
final public function $textSize( $width:Number, $height:Number ):String{
	paramTextSet();
	SELF._paramWidth = $width;
	SELF._paramHeight = $height;
	return '@@textfield';
}